#!/usr/bin/python3
# -*- coding: utf-8 -*-
# ======================================#
# @Author   : duanqizhong
# @time     : 2021-11-6 11:03
# @file     : common.py
# @Software : PyCharm
# ======================================#

import os
import yaml
import hashlib
from apps.config import BASE_DIR


def cryption_md5(strs, encoding="utf-8"):
    md5 = hashlib.md5(strs.encode(encoding=encoding))
    return md5.hexdigest()


def get_yaml_dict(yaml_path):
    assert os.path.isfile(yaml_path), f"not fount yaml_path: {yaml_path}"
    fr = open(file=yaml_path, mode='r', encoding='utf-8')
    yaml_json = yaml.load(stream=fr, Loader=yaml.FullLoader)
    if "handlers" in yaml_json.keys():
        # log.yaml
        for key, value in yaml_json['handlers'].items():
            if "filename" in value:
                value['filename'] = os.path.join(BASE_DIR, value["filename"]).replace("\\", '/')
    return yaml_json


if __name__ == '__main__':
    print(cryption_md5("abc"))
